<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改原因</title>
<%@ include file="/view/common/tags.jsp"%>
<link rel="stylesheet" href="${sysManagerV1}/js/kindeditor/themes/default/default.css" type="text/css"/>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" action="" id="saveAndUpdateFrom" target="_parent"  enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-xs-3 text-right">类型:</label>
				<div class="col-xs-5">
					<sk:select cssClass="form-control select" name="reasonTypeId" id="reasonTypeId" value="" requiredInit="true" ajaxURL="${userInfoV1}/baseType/select?wm[TYPE_FLAG]=60&wm[OPEN_FLAG]=1&wm[DEL_FLAG]=0">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="reasonTypeDes" id="reasonTypeDes" value=""/>
				</div>
			</div>
            <div class="form-group" >
                <label class="col-xs-3 text-right">内容:</label>
                <div class="col-xs-7">
                    <input id="reasonDes" name="reasonDes"  maxlength="30" />
                </div>
            </div>
            <div class="form-group" >
                <label class="col-xs-3 text-right">是否开启:</label>
                <div class="col-xs-7">
                    <td colspan="2">
                        <label><input id="yes" name="useFlag" type="radio" value="1"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label><input id="no" name="useFlag" type="radio" value="0"/>&nbsp;否</label>
                    </td>
                </div>
            </div>
 			<input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>">
           	<input type="hidden" id="token" name="token" value="">
           	<input type="hidden" id="flag"  value="<%=request.getParameter("flag")%>">
           	<input type="hidden" id="isReCommit" value="0">
		</sk:form>	
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script type="text/javascript" charset="UTF-8" src="${sysManagerV1}/js/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" charset="gbk" src="${sysManagerV1}/js/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript">

$(function(){
	$("#token").val(sessionStorage.getItem("token"));
	
	// 初始化
	KindEditor.ready(function(K) {
        ke = K.create("#mapRaider", {
            resizeType : 0,
            urlType : 'domain',
            uploadJson : '${sysManagerV1}/keUploadImg/uploadImg',
            items : [
             'undo', 'redo', '|', 'selectall', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|',
             'quickformat', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor',  'hilitecolor', 'bold', 
             'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'link', 'unlink', 'image', 'emoticons', 'pagebreak', 
             '|', 'justifyleft', 'justifycenter', 
             'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'clearhtml', '|', 'preview', 'source', 'about' 
            ]
        });
    });
    
	var rowId = $("#rowId").val();
	if(rowId > 0){
    	$.ajax({
            url: "${tradeV1}/pubgBaseReasons/getInfo",
            type: "post",
            cache: false,
            data:{"rowId":rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                $("#reasonTypeId").val(data.reasonTypeId);
                $("#reasonTypeDes").val(data.reasonTypeDes);
                $("#reasonDes").val(data.reasonDes);
                if(data.useFlag == 1){
                    $("#yes").attr("checked","true");
                    $("#no").removeAttr("checked");
                } else {
                    $("#yes").removeAttr("checked");
                    $("#no").attr("checked","true");
                }
            }
        });
        $("#reasonTypeId").attr("disabled","true");
	}else{
        $("#yes").attr("checked","true");
    }
})

var err = {'1':'添加','2':'修改'};
var action = {'1':'/save','2':'/update'};
function add(){
    var rowId = $('#rowId').val();
    var i;
    if (!CheckUtil.isNotNull(rowId) || rowId == 0) {
        i = 1;//添加
    } else {
        i = 2;//修改
    }
    var reasonTypeId = $.trim($("#reasonTypeId").val());
    if (!CheckUtil.isNotNull(reasonTypeId)) {
        layer.msg("请选择类型!");
        return;
    }
    var reasonTypeDes = $("#reasonTypeId").find("option:selected").text();
    $("#reasonTypeDes").val(reasonTypeDes);
    
    var reasonDes = $.trim($("#reasonDes").val());
    if (!CheckUtil.isNotNull(reasonDes)) {
        layer.msg("请填写内容!");
        return;
    }
    
    //loading层
    var index = layer.load(0, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    $.ajax({
        url: "${tradeV1}/pubgBaseReasons" + action[i],
        type: "post",
        cache: false,
        data: new FormData($("#saveAndUpdateFrom")[0]),
        dataType:"json",
        processData: false,
        contentType: false,
        async:false,
        success: function(data) {
            layer.close(index);
            if(data.code == 0){
                parent.layer.msg("添加成功！");
            } else if(data.code == 1){
                parent.layer.msg("修改成功！");
            } else if(data.code == "-2"){
                parent.window.location.href="${sysManagerV1}/";
            } else {
                parent.layer.msg(data.message);
            }
            if(data.code >= 0){
                parent.findData();
                parent.layer.close(parent.tableIndex);
            }
        }
    });
}
</script>
</html>